{extend name="layout/main-block" /}
<!-- main content start -->
{block name="content"}
<link href="/static/js/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<section id="main-content">
    <section class="wrapper">
        <div class="row">
            <ol class="breadcrumb">
                <li class="h4"><a href="">新建</a></li>
            </ol>

        </div>
        <div class="row content-main">
            <div class="col-sm-12 col-md-8 col-lg-6">
                <form id="news-add" class="form-horizontal" action="{:url('backend/lists/lists_create',['type'=>$type,'id'=>$id])}" enctype="multipart/form-data" method="post">
                    <div class="form-group ">
                        <label class="col-sm-3 col-md-4 col-lg-3 control-label">tab导航</label>
                        <div id="one" class="col-sm-9 col-md-8  col-lg-9">
                            <!--<div class="row">-->
                            <select class="form-control" name="nav-select3" id="nav-select3">
                                <!-- 循环三级菜单 开始 -->
                                {notempty name="nav3"}
                                {volist name="nav3" id="v"}
                                <option id="input-option" value="{$v.tab_id}">{$v.tab_name_cn}</option>
                                {/volist}
                                {/notempty}
                                <!-- 循环三级菜单 结束 -->
                            </select>
                            <!--</div>-->
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-9">
                            <input id="type_id" type="hidden" name="type_id" value="{$type_id}">
                        </div>
                    </div>
                    <input id="inputManual_sort" type="hidden" name="manual_sort" >
                    <input id="inputIs_recommend" type="hidden" name="is_recommend" >
                    <div class="form-group">
                        <label for="inputList_title_cn" class="col-sm-3  col-md-4 col-lg-3 control-label">名称中文</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input type="text" name="list_title_cn" class="form-control" id="inputList_title_cn" placeholder="名称中文...">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputList_title_en" class="col-sm-3 col-md-4 col-lg-3 control-label">名称英文</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input type="text" name="list_title_en" class="form-control" id="inputList_title_en" placeholder="名称英文...">
                        </div>
                    </div>
                    <div id="newsneed">
                        <div class="form-group">
                            <label class="col-sm-3 col-md-4 col-lg-3 control-label">新闻时间</label>
                            <div class="col-sm-9 col-md-8  col-lg-9">
                                <input type="text" id="datetimepicker" name="news_time" class="form-control"  >
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputTitle_introduce_cn" class="col-sm-3 col-md-4 col-lg-3 control-label">新闻简介中文</label>
                            <div class="col-sm-9 col-md-8  col-lg-9">
                                <textarea name="title_introduce_cn" class="form-control" id="inputTitle_introduce_cn" placeholder="新闻简介中文..."></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputTitle_introduce_en" class="col-sm-3 col-md-4 col-lg-3 control-label">新闻简介英文</label>
                            <div class="col-sm-9 col-md-8  col-lg-9">
                                <textarea name="title_introduce_en" class="form-control" id="inputTitle_introduce_en" placeholder="新闻简介中文..."></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputImg_url" class="col-sm-3 col-md-4 col-lg-3 control-label">新闻图片</label>
                            <div class="col-sm-9 col-md-8  col-lg-9">
                                <input id="inputImg_url" name="image[]" type="file"  value="浏览" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 col-md-4 col-lg-3 control-label">是否应用到其他模块</label>
                            <div class="col-sm-9 col-md-8  col-lg-9">
                                {volist name="check" id="v"}
                                <label class="col-sm-6">
                                    <input class="input-release-name" name="news_id[]" type="checkbox" value="{$v.tab_id}">{$v.tab_name_cn}
                                </label>
                                {/volist}
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-3 col-md-offset-4 col-sm-9 col-md-8  col-lg-9">
                            <button type="submit" class="btn btn-primary">创 建</button>
                            <input type="hidden" id="img_type" name="img_type" value="4">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</section>
{/block}

{block name="javascript"}
<script type="text/javascript" src="/static/js/bootstrap-datetimepicker-master/js/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script>
    $(function (){
        //初始化禁用复选框
        var $news_tab_root = $('#news-add #nav-select1'),
            $news_tab_thir =$('#news-add #nav-select3'),
            $news_title_cn =$('#news-add #inputTitle_cn'),
            $news_title_en=$('#news-add #inputTitle_en'),
            $news_summ_date=$('#news-add #datetimepicker'),
            $news_summ_cn=$('#news-add #inputTitle_introduce_cn'),
            $news_summ_en=$('#news-add #inputTitle_introduce_en'),
            $news_main_image=$('#news-add #inputImg_url'),
            $news_Release_target=$('#news-add #inputRelease');

        function KYinitial(){
            var tab_id = $('#news-add #nav-select3').val();
            var checkbox = $("input[type=checkbox]");
            //console.log(checkbox);

            //绑定select里面的option option的值改变刷新表单最后复选框label的值
            $('#nav-select3').bind('change',function() {
                $(".input-release-name").prop('checked',false);
            });
            for(var i=0;i<checkbox.length;i++){
                if($(checkbox[i]).val()==tab_id){
                    $(checkbox[i]).attr("disabled","disabled");
                    // console.log(checkbox[i]);
                }else{
                    if($(checkbox[i]).attr("disabled")){
                        //$(checkbox[i]).attr("disabled",false);
                        $(checkbox[i]).removeAttr("disabled");
                        // console.log($(checkbox[i]).attr("disabled"));
                    }
                }
            }
        }
        KYinitial();
        //新建新闻页面复选框禁用本身
        $('#nav-select3').change(function (){
            KYinitial();
            //var tab_id = $(this).val();
            //var checkbox = $("input[type=checkbox]");
            //console.log(checkbox);

            /*for(var i=0;i<checkbox.length;i++){
             if($(checkbox[i]).val()==tab_id){
             $(checkbox[i]).attr("disabled","disabled");
             // console.log(checkbox[i]);
             }
             }*/
        });

        $('#nav-select2').change(function (){
            var menu_id = $(this).val();
            var checkbox = $("input[type=checkbox]");
            console.log(checkbox);

            for(var i=0;i<checkbox.length;i++){
                if($(checkbox[i]).val()==menu_id){
                    $(checkbox[i]).attr("disabled","disabled");
                    console.log(checkbox[i]);
                }
            }
        });

        //时间插件
        $('#datetimepicker').datetimepicker({
            format: 'yyyy-mm-dd',
            autoclose:true,
            todayBtn: true
        });

        //级联ajax接收数据
        $("#nav-select1").change(function (){
            var id = $(this).val();
            //console.log($(this).val());
            $.ajax({
                type:"get",
                url:"http://www.leadstar.net/backend/lists/cascade/menu_id/"+id,
                success:function(data){
                    //console.log(data);
                    var str = "";
                    if(data.length>0){
                        for(var i =0;i<data.length;i++){
                            str += "<option value='"+data[i]['tab_id']+"'>"+data[i]['tab_name_cn']+"</option>";
                        }
                    }else{
                        str += "<option value='0'>暂无数据</option>";
                    }
                    $("#nav-select3").html(str);
                    console.log(str);
                },
            });
        });

        //级联ajax接收数据
        $("#nav-select1").change(function (){
            var id = $(this).val();
            //console.log($(this).val());
            $.ajax({
                type:"get",
                url:"http://www.leadstar.net/backend/lists/cascade2/menu_id/"+id,
                success:function(data){
                    //console.log(data);
                    var str = "";
                    if(data.length>0){
                        for(var i =0;i<data.length;i++){
                            str += "<option value='"+data[i]['menu_id']+"'>"+data[i]['menu_name_cn']+"</option>";
                        }
                    }else{
                        str += "<option value='0'>暂无数据</option>";
                    }
                    $("#nav-select2").html(str);
                    console.log(str);
                },
            });
        });

        //级联ajax接收数据
        $("#nav-select2").change(function (){
            var id = $(this).val();
            //console.log($(this).val());
            $.ajax({
                type:"get",
                url:"http://www.leadstar.net/backend/lists/cascade/menu_id/"+id,
                success:function(data){
                    //console.log(data);
                    var str = "";
                    if(data.length>0){
                        for(var i =0;i<data.length;i++){
                            str += "<option value='"+data[i]['tab_id']+"'>"+data[i]['tab_name_cn']+"</option>";
                        }
                    }else{
                        str += "<option value='0'>暂无数据</option>";
                    }
                    $("#nav-select3").html(str);
                    console.log(str);
                },
            });
        });
       // $("#newsneed").addClass('green');
        //新闻跟文章模板不同
        var type_id ='{$type_id}';
        console.log(type_id);
        if(type_id ==1){
            $("#newsneed").css("display","block");//显示div
        }else if(type_id == 2){
           // $("#newsneed").addClass('green');
            $("#newsneed").css("display","none");//隐藏div
        }

        //图片上传
       /* var firstFlag = secondFlag = false;
        $('input[type=file]').each(function (index, ele) {
            // 判断 hidden 控件的值（两个文件上传控件index+1 后的和值）
            // 如果最后值是1，说明是上传的第一个文件
            // 如果最后值是2，说明是上传的第二个文件
            var index2 = index + 1;
            //console.log($('input#img_type').val());
            // 选择一个文件后触发此事件，表明一定是选择了文件
            $(this).change(function (e) {
                // 如果本次上传的是第一个文件，并且第一个文件控件之前点击后
                if(!(((index2 == 1) && firstFlag) || ((index2 == 2) && secondFlag)))
                {
                    $('input#img_type').val(parseInt(parseInt($('input#img_type').val()) + index2));
                }

                if(index2 == 1)
                {
                    firstFlag = true;
                } else if (index2 == 2){
                    secondFlag = true;
                }
                //console.log($('input#img_type').val());
            });
        });*/



    });
</script>
{/block}

